// NotifyDlg.cpp : implementation file
//

#include "stdafx.h"
#include "EventNotify.h"
#include "NotifyDlg.h"
#include "afxdialogex.h"


// CNotifyDlg dialog

IMPLEMENT_DYNAMIC(CNotifyDlg, CDialogEx)

CNotifyDlg::CNotifyDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CNotifyDlg::IDD, pParent)
	, m_strCap(_T(""))
	, m_strMsg(_T(""))
	, m_strSound(_T(""))
	, m_iSoundTimeout(0)
{

}

CNotifyDlg::~CNotifyDlg()
{
}

void CNotifyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_CAPITION, m_CapitionCtrl);
	DDX_Text(pDX, IDC_STATIC_CAPITION, m_strCap);
	DDX_Text(pDX, IDC_STATIC_MSG, m_strMsg);
}


BEGIN_MESSAGE_MAP(CNotifyDlg, CDialogEx)
	ON_WM_CTLCOLOR()
	ON_WM_TIMER()
END_MESSAGE_MAP()


// CNotifyDlg message handlers


BOOL CNotifyDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  Add extra initialization here
	CFont *pfOldFont = m_CapitionCtrl.GetFont();
	LOGFONT lfFont;
	
	pfOldFont->GetLogFont(&lfFont);
	lfFont.lfHeight = 25;
	m_fCapFont.Detach();
	m_fCapFont.CreateFontIndirect(&lfFont);
	m_CapitionCtrl.SetFont(&m_fCapFont);

	if(m_strSound.GetLength() > 4)
	{
		PlaySound(m_strSound, 0, SND_FILENAME | SND_ASYNC | SND_LOOP);
		if(m_iSoundTimeout)
			SetTimer(ID_TIMER_SOUND, m_iSoundTimeout * 1000, NULL);
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


HBRUSH CNotifyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	if(pWnd->GetDlgCtrlID() == IDC_STATIC_CAPITION)
		pDC->SetTextColor(RGB(200, 0, 0));

	// TODO:  Change any attributes of the DC here

	// TODO:  Return a different brush if the default is not desired
	return hbr;
}

void CNotifyDlg::OnCancel()
{
	// TODO: Add your specialized code here and/or call the base class
	if(m_strSound.GetLength() > 4)
	{
		PlaySound(NULL, 0, 0);
	}
	CDialogEx::OnCancel();
}


void CNotifyDlg::OnTimer(UINT_PTR nIDEvent)
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent == ID_TIMER_SOUND)
	{
		PlaySound(NULL, 0, 0);
		KillTimer(ID_TIMER_SOUND);
	}

	CDialogEx::OnTimer(nIDEvent);
}


void CNotifyDlg::OnFinalRelease()
{
	// TODO: Add your specialized code here and/or call the base class
	if(m_strSound.GetLength() > 4)
	{
		PlaySound(NULL, 0, 0);
	}

	CDialogEx::OnFinalRelease();
}
